package com.zzw.mvvm.pages.demo;


import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;

import com.zzw.mvvm.MainActivity;
import com.zzw.mvvm.R;
import com.zzw.mvvm.base.BaseActivity;

import butterknife.BindView;

public class WebActivity extends BaseActivity {


    @BindView(R.id.web_demo)
    WebView webDemo;

    @Override
    public int getLayoutId() {
        return R.layout.activity_web;
    }

    @Override
    public void bindViewModel() {
        JavaScriptInterface JSInterface;

        webDemo.getSettings().setJavaScriptEnabled(true); ///------- 设置javascript 可用
        JSInterface = new JavaScriptInterface(this); ////------
        webDemo.addJavascriptInterface(JSInterface, "JSInterface"); // 设置js接口  第一个参数事件接口实例，第二个是实例在js中的别名，这个在js中会用到
        webDemo.loadUrl("http://192.168.0.99:8081/rdrrc_interface/success.jsp");
    }

    public class JavaScriptInterface {
        Context mContext;

        JavaScriptInterface(Context c) {
            mContext = c;
        }

        @JavascriptInterface
        public void changeActivity() {
            Log.i("zzw","changeActivity");
            Intent i = new Intent(WebActivity.this, MainActivity.class);
            startActivity(i);
            finish();
        }
    }
}
